package com.borened.common.boot.config.properties;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 登录认证白名单配置(同网关中的白名单配置属性，仅仅因为网关依赖最小化，故重复定义此类。)
 * <pre>
 *   @see  com.borened.common.boot.interceptor.JwtInterceptor
 * </p>
 * @author cch
 */
@Component("ignoreWhiteProperties")
@ConfigurationProperties(prefix = "security.ignore")
public class IgnoreWhiteProperties implements InitializingBean {
    /**
     * 默认的排除路径，排除Spring Boot默认的错误处理路径和端点
     */
    private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error", "/actuator/**");

    /**
     * 放行白名单配置，JwtInterceptor不会拦截白名单
     */
    private List<String> whites = new ArrayList<>();

    public List<String> getWhites() {
        return whites;
    }

    public void setWhites(List<String> whites) {
        this.whites = whites;
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        this.whites.addAll(DEFAULT_EXCLUDE_PATH);
    }
}
